package com.crm.controller.system;


import com.crm.aonnation.Log;
import com.crm.dto.QueryDictDataDto;
import com.crm.pojo.Dict;
import com.crm.pojo.DictData;
import com.crm.pojo.Referredsubject;
import com.crm.result.ResponseResult;
import com.crm.result.Result;
import com.crm.service.system.DictDataService;

import com.crm.vo.ActivityStatusVO;
import com.crm.vo.ChannelTypeVO;
import com.github.pagehelper.Page;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author Xanny
 * @RequestMapping("/system/dict/data")
 */
@RestController
@Slf4j
public class DictDataController {
    @Autowired
    private DictDataService dataService;

    /**
     * 分页查询
     */

    @GetMapping("/system/dict/data/list")
    public ResponseResult searchList(QueryDictDataDto dto) {
        Page<DictData> page = dataService.queryAll(dto);
        return ResponseResult.success()
                .put("rows", page.getResult())
                .put("total", page.getTotal());
    }
    /**
     * 新增
     */
    @PostMapping("/system/dict/data")
    public ResponseResult add(@RequestBody DictData dictData) {
        dataService.add(dictData);
        return ResponseResult.success();
    }

    /**
     * 根据dictCode查询
     *
     * @param dictCode
     * @return
     */
    @GetMapping("/system/dict/data/{dictCode}")
    public Result<DictData> getByDictCode(@PathVariable("dictCode") Integer dictCode) {
        DictData dictData = dataService.getByDictCode(dictCode);
        return Result.success(dictData);
    }

    @PutMapping("/system/dict/data")
    public ResponseResult update(@RequestBody DictData dictData) {
        dataService.update(dictData);
        return ResponseResult.success();
    }


    @DeleteMapping("/system/dict/data/{dictCodes}")
    public ResponseResult delete(@PathVariable("dictCodes") List<Integer> dictCodes) {
        dataService.delete(dictCodes);
        return ResponseResult.success();
    }

    //新增时 活动类型查询
    @GetMapping("/system/dict/data/type/{type}")
    public Result getType(@PathVariable String type) {
        List<Referredsubject> referredsubject = dataService.getType(type);
        return Result.success(referredsubject);
    }
}
